
#import "YQOrderRefundShowView.h"

#import "YQOrderRefundVC.h"

#import "YQGoodsActionOrderDetailsVC.h"
#import "YQGoodsOrderDetailsModel.h"
@interface YQGoodsActionOrderDetailsVC ()<YQGoodsScenicspotOrderDetailsCellDelegate>

@end

@implementation YQGoodsActionOrderDetailsVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if(section == 1){
        return 3;
    }else if (section == 3){
        return 6;
    }else if (section == 2) {
        return 2;
    }else if (section == 4){
        return 4;
    }
    return 1;
}

- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        YQGoodsOrderItemModel *model = self.orderDetailsModel.orderItemList[indexPath.row];

        YQGoodsScenicspotOrderDetailsCell *goodsCell = [tableView dequeueReusableCellWithIdentifier:@"YQGoodsScenicspotOrderDetailsCell"];
        goodsCell.titleLb.text = self.goodsOrderModel.specification;
        goodsCell.specificationLb.text = self.goodsOrderModel.standardDesc;
        goodsCell.priceLb.text = [NSString stringWithFormat:@"HKD%.2lf",self.goodsOrderModel.goodsPrice];
        goodsCell.numLb.text = [NSString stringWithFormat:@"x%zd",self.goodsOrderModel.goodsNum];
        [goodsCell setRefundSceneMoreModel:self.orderDetailsModel :indexPath];
        [goodsCell setRefundSceneDetailModel:NSStringFormat(@"%ld",(long)self.orderDetailsModel.orderStatus) :model.refundStatus];
        [goodsCell.goodIcon sd_setImageWithURL:kURL(model.goodsImg) placeholderImage:IMAGE_NAMED(@"")];
        goodsCell.delegate = self;
        
        return goodsCell;
    }else if (indexPath.section == 1) {
        YQOrderDetailsMoneyCell *moneyCell = [tableView dequeueReusableCellWithIdentifier:@"YQOrderDetailsMoneyCell"];
        NSString *title = @"";
        NSString *subTitle = @"";
        if (indexPath.row == 0) {
            title = kYQLS(@"商品金额");
            subTitle = [NSString stringWithFormat:@"HKD%@",self.orderDetailsModel.goodAmount];
        }else if (indexPath.row == 1){
            title = kYQLS(@"优惠折扣");
            
            subTitle = [NSString stringWithFormat:@"-HKD%@",self.orderDetailsModel.couponAmount];
            if (self.orderDetailsModel.couponAmount.intValue == 0 || IsStrEmpty(self.orderDetailsModel.couponAmount)) {
                moneyCell.labSubTitle.hidden = YES;

            }else{
                moneyCell.labSubTitle.hidden = NO;

            }
        }else{
            title = kYQLS(@"订单实付款");
            subTitle = [NSString stringWithFormat:@"HKD%@",self.orderDetailsModel.payAmount];
        }
        moneyCell.labSubTitle.text = subTitle;
        moneyCell.labTitle.text = title;
        return moneyCell;
    }else if (indexPath.section == 2) {
        YQOrderDetailsInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YQOrderDetailsInfoCell"];
        NSString *title = @"";
        NSString *subTitle = @"";
        if (indexPath.row == 0) {
            title = [NSString stringWithFormat:@"%@ :",kYQLS(@"时间")];
            if (IsStrEmpty(self.orderDetailsModel.endTime) || IsStrEmpty(self.orderDetailsModel.startTime)) {
                cell.infoLb.hidden = YES;
            }else{
                cell.infoLb.hidden = NO;

            }
            subTitle = NSStringFormat(@"%@%@-%@%@",kYQLS(@"即"),kYQLS(self.orderDetailsModel.startTime),kYQLS(@"起至"),kYQLS(self.orderDetailsModel.endTime)) ;
        }else{
            title = [NSString stringWithFormat:@"%@:",kYQLS(@"地址")];
             subTitle = self.orderDetailsModel.address;
        }
        cell.titleLb.text = title;
        cell.infoLb.text = subTitle;
        return cell;
    }else if (indexPath.section == 3) {
        YQOrderDetailsInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YQOrderDetailsInfoCell"];
        NSString *title = @"";
        NSString *subTitle = @"";
        if (indexPath.row == 0) {
            title = [NSString stringWithFormat:@"%@:",kYQLS(@"姓名")];
            subTitle = self.orderDetailsModel.userName;
        }else if (indexPath.row == 1){
            title = [NSString stringWithFormat:@"%@ :",kYQLS(@"性别")];
            subTitle = self.orderDetailsModel.userSex == 0 ? kYQLS(@"女"):kYQLS(@"男");
        }else if(indexPath.row == 2) {
            title = [NSString stringWithFormat:@"%@ :",kYQLS(@"出生日期")];
            subTitle = self.orderDetailsModel.userBirthday;
        }else if(indexPath.row == 3) {
            title = [NSString stringWithFormat:@"%@ :",kYQLS(@"电子邮箱")];
            subTitle = self.orderDetailsModel.userEmail;
        }else if(indexPath.row == 4) {
            title = [NSString stringWithFormat:@"%@ :",kYQLS(@"联络电话")];
            subTitle = self.orderDetailsModel.userPhone;
        }else{
            title = [NSString stringWithFormat:@"%@ :",kYQLS(@"居住地址")];
            subTitle = self.orderDetailsModel.userAddress;
        }
        cell.titleLb.text = title;
        cell.infoLb.text = subTitle;
        return cell;
    }else{
        YQOrderDetailsInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YQOrderDetailsInfoCell"];
        NSString *title = @"";
        NSString *subTitle = @"";
        if (indexPath.row == 0) {
             title =[NSString stringWithFormat:@"%@ :",kYQLS(@"订单编号")];
            subTitle = self.orderDetailsModel.orderSn;
        }else if (indexPath.row == 1){
            title = [NSString stringWithFormat:@"%@ :",kYQLS(@"订单创建时间")];
            subTitle = self.orderDetailsModel.createTime;
        }else if (indexPath.row == 2) {
            title = [NSString stringWithFormat:@"%@ :",kYQLS(@"支付时间")];
            subTitle = self.orderDetailsModel.paymentTime;
        }else{
            title =[NSString stringWithFormat:@"%@ :",kYQLS(@"备注")];
            subTitle = self.orderDetailsModel.note;
        }
        cell.titleLb.text = title;
        cell.infoLb.text = subTitle;
        return cell;
    }
}

#pragma mark - YQGoodsScenicspotOrderDetailsCellDelegate
//售后退货退款
- (void)selectSceneGoodItemModel:(YQGoodsOrderItemModel *)model
{
    [YQOrderRefundShowView refundShowViewViewResultBlack:^(NSInteger row) {
            YQOrderRefundVC *refundVC = [[YQOrderRefundVC alloc] init];
            refundVC.type = row;//
            refundVC.OrderModel = model;
            refundVC.detailModel = self.orderDetailsModel;
            ws(self);
            refundVC.ssucceeBlock = ^{
    //            [weakself getDetailsData];
            };
            [weakself.navigationController pushViewController:refundVC animated:true];
        }];
}
//撤销
- (void)selectSceneCancelGoodItemModel:(YQGoodsOrderItemModel *)detailModel
{
    [self selectResetGoodItemModel:detailModel];
}
#pragma mark - 撤销
- (void)selectResetGoodItemModel:(YQGoodsOrderItemModel *)model
{
    NSMutableDictionary *params = NSMutableDictionary.new;
//    params[@"refundId"] = @"0";
    params[@"orderItemId"] = model.orderItemId;
    params[@"orderType"] = @(self.orderDetailsModel.orderType);

    YQSHOWLOADINGINVIEW
    [YQPNetWorkingManager sendPostRequest:kPOST_REFUND_CANCEL_URL parameters:params success:^(YQPNetWorkingBaseModel * _Nonnull responseObject) {
        [self stopRefresh];
        YQHIDELOADINGTIPS
        if (responseObject.code == 0) {
            kMBMesHUD(kYQLS(@"撤销成功"));
            [self getDetailsData];
        }else{
            YQUITIPSERROR(responseObject.msg)
        }
    } failure:^(NSUInteger statusCode, NSString * _Nonnull error) {
        YQHIDELOADINGTIPS
        [self stopRefresh];
    }];
}

@end
